﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace GeoSketch2.Core
{
    /// <summary>
    /// The base class for the capture tools toolbar button
    /// </summary>
    public partial class BaseCaptureToolbarButton : BaseToolbarButton
    {
        #region Constructor
        /// <summary>
        /// The base class for the capture tools toolbar button
        /// </summary>
        public BaseCaptureToolbarButton()
            : base()
        {
        } 
        #endregion

        #region Events
        /// <summary>
        /// The action when pressing a mouse button
        /// </summary>
        protected override void OnMouseClick(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
            {
                if (LeftButtonClicked)
                {
                    ((BaseCaptureTool)DisplayBox.LeftClicTool).RestoreCapturedTool();
                }
                else
                {
                    SetTool(GetTool(e.Button), sender, e);
                    ((BaseCaptureTool)DisplayBox.LeftClicTool).CapturedTool.ToolbarButton.LeftButtonClicked = true;

                    foreach (Control tbb in this.Parent.Controls)
                    {
                        if (tbb.GetType().BaseType == typeof(BaseCaptureToolbarButton))//ResSet every other button
                        {
                            ((BaseToolbarButton)tbb).LeftButtonClicked = false;
                            tbb.Invalidate();
                        }
                    }
                }
                LeftButtonClicked = !LeftButtonClicked;
            }
            else if (e.Button == MouseButtons.Right)
            {
                if (RightButtonClicked)
                {
                    ((BaseCaptureTool)DisplayBox.RightClicTool).RestoreCapturedTool();
                }
                else
                {
                    SetTool(GetTool(e.Button), sender, e);
                    ((BaseCaptureTool)DisplayBox.RightClicTool).CapturedTool.ToolbarButton.RightButtonClicked = true;

                    foreach (Control tbb in this.Parent.Controls)
                    {
                        if (tbb.GetType().BaseType == typeof(BaseCaptureToolbarButton))//ResSet every other button
                        {
                            ((BaseToolbarButton)tbb).RightButtonClicked = false;
                            tbb.Invalidate();
                        }
                    }
                }
                RightButtonClicked = !RightButtonClicked;
            }
            this.Invalidate();
        } 
        #endregion

        #region Methods
        /// <summary>
        /// Gets the tool assigned to the toolbar button
        /// </summary>
        protected virtual BaseCaptureTool GetTool(MouseButtons e)
        {
            return null;
        }
        #endregion
    }
}
